#pragma once

MAPPING_VALUE(DriveMode, sdb::DrvModReqType2, sdb::DrvModReqType2::DrvModReqType1_Undefd)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_UNDEFINED, sdb::DrvModReqType2::DrvModReqType1_Undefd)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_ECO, sdb::DrvModReqType2::DrvModReqType1_ECO)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_COMFORT, sdb::DrvModReqType2::DrvModReqType1_Comfort_Normal)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_DYNAMIC, sdb::DrvModReqType2::DrvModReqType1_Dynamic_Sport)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_INDIVIDUAL, sdb::DrvModReqType2::DrvModReqType1_Individual)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_OFFROAD, sdb::DrvModReqType2::DrvModReqType1_Offroad_CrossTerrain)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_ADAPTIVE, sdb::DrvModReqType2::DrvModReqType1_Adaptive)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_RACE, sdb::DrvModReqType2::DrvModReqType1_Race)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_PURE, sdb::DrvModReqType2::DrvModReqType1_Pure_EV)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_HYBRID, sdb::DrvModReqType2::DrvModReqType1_Hybrid)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_POWER, sdb::DrvModReqType2::DrvModReqType1_Power)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_SNOW, sdb::DrvModReqType2::DrvModReqType1_Snow)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_SAND, sdb::DrvModReqType2::DrvModReqType1_Sand)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_MUD, sdb::DrvModReqType2::DrvModReqType1_Mud)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_ROCK, sdb::DrvModReqType2::DrvModReqType1_Rock)
    MAPPING_ITEM(DriveMode::DRIVE_MODE_SELECTION_ERROR, sdb::DrvModReqType2::DrvModReqType1_Err)
MAPPING_END

MAPPING_VALUE(sdb::DrvModReqType2, DriveMode, DriveMode::DRIVE_MODE_SELECTION_UNDEFINED)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Undefd, DriveMode::DRIVE_MODE_SELECTION_UNDEFINED)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_ECO, DriveMode::DRIVE_MODE_SELECTION_ECO)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Comfort_Normal, DriveMode::DRIVE_MODE_SELECTION_COMFORT)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Dynamic_Sport, DriveMode::DRIVE_MODE_SELECTION_DYNAMIC)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Individual, DriveMode::DRIVE_MODE_SELECTION_INDIVIDUAL)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Offroad_CrossTerrain, DriveMode::DRIVE_MODE_SELECTION_OFFROAD)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Adaptive, DriveMode::DRIVE_MODE_SELECTION_ADAPTIVE)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Race, DriveMode::DRIVE_MODE_SELECTION_RACE)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Pure_EV, DriveMode::DRIVE_MODE_SELECTION_PURE)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Hybrid, DriveMode::DRIVE_MODE_SELECTION_HYBRID)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Power, DriveMode::DRIVE_MODE_SELECTION_POWER)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Snow, DriveMode::DRIVE_MODE_SELECTION_SNOW)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Sand, DriveMode::DRIVE_MODE_SELECTION_SAND)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Mud, DriveMode::DRIVE_MODE_SELECTION_MUD)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Rock, DriveMode::DRIVE_MODE_SELECTION_ROCK)
    MAPPING_ITEM(sdb::DrvModReqType2::DrvModReqType1_Err, DriveMode::DRIVE_MODE_SELECTION_ERROR)
MAPPING_END

namespace ecarx::vhal::core::property::DriveModeSelectUtil {
    inline DriveMode getDefaultDriveMode() {
        if (SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_01, sdb::CarConfig13::_02,
            sdb::CarConfig13::_04, sdb::CarConfig13::_80)) {
            return DriveMode::DRIVE_MODE_SELECTION_COMFORT;
        }
        return DriveMode::DRIVE_MODE_SELECTION_UNDEFINED;
    }

    inline bool isPersist() {
        VHALOG.d("DriveModeSelectUtil isPersist cc13: %d, cc220: %d", SIGNAL.getcarconfig13(), SIGNAL.getcarconfig220());
        return SIGNAL.carConfigIs(SignalRX::carconfig220, sdb::CarConfig220::_0A) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_04);
    }
}

using namespace ::ecarx::vhal::core::property::DriveModeSelectUtil;
